package com.basic.meiju;

import org.junit.jupiter.api.Test;

import java.util.Arrays;

public class EnumTest {

    @Test
    public void test0() {
        System.out.println(MySeasonEnum.SPRING); // MySeasonEnum{name='春天', characteristic='鸟女花香'}
    }

    @Test
    public void test1() {
        System.out.println(Season.SPRING.name()); // SPRING
        System.out.println(Season.SPRING); // Season{name='春天', characteristic='鸟女花香'}

        System.out.println(Season.AUTUMN.ordinal()); // 索引， 从 0 开始，按照定义的顺序， AUTUMN 值为 2

        Arrays.stream(Season.values()).forEach(System.out::println);

        System.out.println(Season.valueOf("SPRING")); // Season{name='春天', characteristic='鸟女花香'}

//      枚举的  compareTo 实际上是 前面索引  减去 参数的 枚举索引，下面例子是  0 -2 = -2
        System.out.println(Season.SPRING.compareTo(Season.AUTUMN));
    }

    @Test
    public void test2() {
        System.out.println(SeasonEnum.SPRING.name()); // SPRING
        System.out.println(SeasonEnum.SPRING); // SPRING
        System.out.println(SeasonEnum.SPRING.ordinal()); // 0

//        Arrays.stream(SeasonEnum.values()).forEach((item) -> {
//            System.out.println(item);
//        });
        Arrays.stream(SeasonEnum.values()).forEach(System.out::println);
    }

    @Test
    public void test3() {
        switch (SeasonEnum.FALL) {
            case SPRING:
                System.out.println("春天");
                break;
            case SUMMER:
                System.out.println("夏天");
                break;
            case FALL:
                SeasonEnum FALL = SeasonEnum.FALL;
                // 获取序号，默认第一个是从 0 开始的
                System.out.println(FALL.ordinal());
                System.out.println(FALL.toString());
                System.out.println("秋天");
                break;
            case WINTER:
                System.out.println("冬天");
                break;
        }
    }

    @Test
    public void test4() {
        Weekday day = Weekday.SUN; // 枚举的值 和 枚举类是一致的
        if (day == Weekday.SAT || day == Weekday.SUN) {
            System.out.println("Work at home!");
        } else {
            System.out.println("Work at office!");
        }
    }


//    @Test
//    public void test1() {}


//    @Test
//    public void test1() {}


//    @Test
//    public void test1() {}


}
